// 此处存放所有的请求链接，用于和后端业务接口对接
// 使用方法：
// 引入方式 const API_BUSI = require("../../../utils/api_busi")
// 调用方法 API_BUSI.activity();
const API_UTILS = require("./api_utils");
const config = require("./config");
let prefixUrl = {
  common:      "/api/applet",
  activity:    "/v2/api/applet/activity",
  commonly:    "/v2/api/applet/commonly",
  manager:     "/v2/api/applet/commonly/activity/manager",
  userMessage: "/v2/api/applet/commonly/userMessage",
  answer:      "/v2/api/applet/activity/answer"
};
let transUrl = function(url,type) {
  if(type){
    return config.pageDomain + prefixUrl[type] + url;
  }else{
    return config.pageDomain + url;
  }
}
let urls = {
  common:{
    USER:                   transUrl('/user/manager/user',"common"), // 用户信息
    INIT:                   transUrl('/scene/lottery/init',"common"), //初始化
    CONFIG_CONTENT:         transUrl('/global/config/content',"common"), //配置项或更新配置项
    SCENE:                  transUrl('/scene',"common")// 场景值获取
  },
  activity:{
    ACTIVITY_CONFIG:        transUrl('/red/envelop/activity/manager/config',"activity"), //创建或编辑活动
    CARD_LIST:              transUrl('/card/manager/cardlist',"activity"),//贺卡列表
    CARD_CATEGORY:          transUrl('/card/manager/category',"activity"),//贺卡分类
    RECEIVE_FLOW:           transUrl('/red/envelop/activity/manager/receiveFlow',"activity"), //我收到的红包的流水
  },
  commonly:{
    CREAT_WX_PAY_ORDER:     transUrl('/wxpay/createWxPayOrder',"commonly"), //生成订单
    QRCode:                 transUrl('/scene/manager/generate/applet/QR/code',"commonly"), //生成二维码
    REDPACK_COUNT:          transUrl('/user/manager/user/personalCenter',"commonly"), //我发出的红包和我收到的红包数量
    GET_QINIU_TOKEN:        transUrl('/qiniu/getQiniuToken',"commonly"), //获取七牛token
  },
  manager:{
    ACTIVITY_LIST:          transUrl('/home/page/activity/list',"manager"), // 活动列表
    ACT_DETAIL:             transUrl('/activity/detail',"manager"),//活动详情
    PARTICIPATE:            transUrl('/redpack/participate',"manager"),//用户参与抽奖活动
    PRIZE_INFO:             transUrl('/redpack/activity/prizeinfo',"manager"), //查询活动的红包记录
    WIN_PRIZE:              transUrl('/redpack/activity/win/prize',"manager"),//查询用户的红包记录
  },
  userMessage:{
    ADD_REDPACK:            transUrl('/addRedPack',"userMessage"), //添加回赏记录
    FIND_NO_READ:           transUrl('/findNoRead',"userMessage"), //查询该用户未领取的回赏
    GET_BALANCE:            transUrl('/selectAccount',"userMessage"), //获取余额
    REDPACK_RECORD_SEND:    transUrl('/activityPage',"userMessage"),//红包记录(发出)
    READLIST:               transUrl('/readList',"userMessage"), //已读回赏（列表）
    WITHDRAWAL:             transUrl('/withdrawal',"userMessage"), //提现
  },
  answer:{
    GETRANDOM:              transUrl('/getRandom',"answer"), //随机返回一道题
    GETRANDOM_KNOWYOU:      transUrl('/knowYou/getRandom',"answer"), //随机返回一道题(懂你红包)
    GETTYPE:                transUrl('/getType',"answer"), //返回题目类型
    GETLISTBYTYPE:          transUrl('/getListByType',"answer"), //通过题目类型获取分页列表
    GETLIST_KNOWYOU:        transUrl('/knowYou/getList',"answer"), //通过题目类型获取分页列表(懂你红包)
    GETBYSCENE:             transUrl('/knowYou/getByScene',"answer"), //通过 scene 查询题库(懂你红包)
    START:                  transUrl('/start',"answer"), //用户通过活动id参与活动
    GETNEXT:                transUrl('/getNext',"answer"), //答题获取下一题
  }
};
let API_BUSI = {
  common:{
    user: function (data, success, fail) {
      API_UTILS.ajax({ "data": data, url: urls.common.USER }, success, fail);
    },
    init: function (data, success, fail) {
      API_UTILS.ajax({ "data": data, url: urls.common.INIT }, success, fail);
    },
    config_content: function (data, success, fail) {
      API_UTILS.ajax({ "data": data, url: urls.common.CONFIG_CONTENT }, success, fail);
    },
    config_content_update: function (data, success, fail) {
      API_UTILS.ajax({ "data": data, url: urls.common.CONFIG_CONTENT, method:'POST' }, success, fail);
    },
    parseScene: function (data, success, fail) {// 解析场景值
      API_UTILS.ajax({ "data": data, url: urls.common.SCENE }, success, fail);
    },
    createScene: function (data, success, fail) {// 生成场景值
      API_UTILS.ajax({ "data": data, url: urls.common.SCENE, method:'POST' }, success, fail);
    },
  },
  activity:{
    activity_config: function (data, success, fail) {
      API_UTILS.ajax({ "data": data, url: urls.activity.ACTIVITY_CONFIG, method: 'POST' }, success, fail);
    },
    card_list: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.activity.CARD_LIST}, success, fail);
    },
    card_category: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.activity.CARD_CATEGORY}, success, fail);
    },
    receive_flow: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.activity.RECEIVE_FLOW}, success, fail);
    }
  },
  commonly:{
    create_wx_pay_order: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.commonly.CREAT_WX_PAY_ORDER,method:'POST'}, success, fail);
    },
    generate_qrcode: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.commonly.QRCode, method: 'POST'}, success, fail);
    },
    redpack_count: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.commonly.REDPACK_COUNT}, success, fail);
    },
    get_qiniu_token: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.commonly.GET_QINIU_TOKEN}, success, fail);
    }
  },
  manager:{
    activityList: function (data, success, fail) {
      API_UTILS.ajax({ "data": data, url: urls.manager.ACTIVITY_LIST }, success, fail);
    },
    act_detail: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.manager.ACT_DETAIL}, success, fail);
    },
    participate: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.manager.PARTICIPATE, method: 'POST'}, success, fail);
    },
    prize_info: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.manager.PRIZE_INFO}, success, fail);
    },
    win_prize: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.manager.WIN_PRIZE}, success, fail);
    }
  },
  userMessage:{
    add_redpack: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.userMessage.ADD_REDPACK,method: 'POST'}, success, fail);
    },
    find_no_read: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.userMessage.FIND_NO_READ}, success, fail);
    },
    get_balance: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.userMessage.GET_BALANCE}, success, fail);
    },
    read_list: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.userMessage.READLIST,method: 'POST'}, success, fail);
    },
    redpack_record_send: function (data, success, fail) {
      API_UTILS.ajax({ "data": data, url: urls.userMessage.REDPACK_RECORD_SEND }, success, fail);
    },
    withdrawal: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.userMessage.WITHDRAWAL,method: 'POST'}, success, fail);
    }
  },
  answer:{
    getRandom: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.answer.GETRANDOM}, success, fail);
    },
    getRandom_knowYou: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.answer.GETRANDOM_KNOWYOU}, success, fail);
    },
    getType: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.answer.GETTYPE}, success, fail);
    },
    getListByType: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.answer.GETLISTBYTYPE}, success, fail);
    },
    getByScene: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.answer.GETBYSCENE}, success, fail);
    },
    getList_knowYou: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.answer.GETLIST_KNOWYOU}, success, fail);
    },
    start: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.answer.START,method: 'POST'}, success, fail);
    },
    getNext: function(data, success, fail){
      API_UTILS.ajax({ "data": data, url: urls.answer.GETNEXT}, success, fail);
    },
  }
}

module.exports = API_BUSI;
